import { store } from '@/store';
import { defineStore } from 'pinia';
import {findDictList} from "@/api/system/dict";

export interface IDictState {
  dictList: any[]
}
export const useDictStore = defineStore({
  id:'dict',
  state:():IDictState=>({
    dictList:[]
  }),
  getters:{
    getDict():any[]{
      return this.dictList;
    }
  },
  actions:{
    setDictList(dictList:[]){
      this.dictList=dictList;
    },
    async loadDict(){
      try{
       let response= await findDictList();
        this.setDictList(response);
        return Promise.resolve(response);
      }catch (e){
        return Promise.reject(e);
      }
    }
  }
})
export function useDictStoreWidthOut() {
  return useDictStore(store);
}
